clear;
close all;
warning('off','all');
paths;

load('soln.mat');
load('data.mat');

T = height(data); t = datetime(1977,12,31) + calquarters(1:1:T);

figure;
hold on;  
area(t, data.px1_educg1 - data.f_inflation, 'LineStyle','none', 'FaceAlpha', 0.7);
area(t, data.px1_educg3 - data.f_inflation, 'LineStyle','none', 'FaceAlpha', 0.8); 
area(t, data.spf - data.f_inflation, 'LineStyle','none', 'FaceAlpha', 0.3); 
%colororder([0.4940 0.1840 0.5560; 0 0.4470 0.7410; 0.8500 0.3250 0.0980]);
xtickformat('yyyy');
legend('boxoff');
legend({'non-college', 'college', 'professional'},'fontsize', 12); box off;
ylabel('forecast errors of annualized inflation', 'fontsize', 15);
set(gca, 'ColorOrder', colormap(gray(3)))
set(gcf,'position',[0,0,1000,500]); fontsize(gcf,scale=1.5);
saveas(gcf,"figures/error.eps",'epsc'); 


figure;
hold on;
plot(t, phi(1,:), ':', 'LineWidth',2.5, 'Color', [0.9290 0.6940 0.1250]); 
plot(t, phi(2,:), '--', 'LineWidth',2.5, 'Color', [0.4940 0.1840 0.5560]); 
plot(t, phi(3,:), '-.', 'LineWidth',2.5,'Color', [0 0.4470 0.7410]); 
plot(t, phi(4,:), '-', 'LineWidth',2.5,'Color', [0.8500 0.3250 0.0980]); 
xtickformat('yyyy');
legend('boxoff');
legend({'actual', 'SPF', 'non-college', 'college'},'fontsize', 12); box off;
ylabel('\phi', 'fontsize', 18);
set(gcf,'position',[0,0,1000,500]); fontsize(gcf,scale=1.5);
style = hgexport('factorystyle'); style.Color = 'gray';
hgexport(gcf,"figures/phi.eps",style);


figure;
hold on;
plot(t, alpha(1,:), ':', 'LineWidth',2.5, 'Color', [0.9290 0.6940 0.1250]); 
plot(t, alpha(2,:), '--', 'LineWidth',2.5, 'Color', [0.4940 0.1840 0.5560]); 
plot(t, alpha(3,:), '-.', 'LineWidth',2.5,'Color', [0 0.4470 0.7410]); 
plot(t, alpha(4,:), '-', 'LineWidth',2.5,'Color', [0.8500 0.3250 0.0980]); 
xtickformat('yyyy');
legend('boxoff');
legend({'actual',   'SPF',  'non-college',  'college'},'fontsize', 12); box off;
ylabel('\alpha', 'fontsize', 18);
set(gcf,'position',[0,0,1000,500]); fontsize(gcf,scale=1.5);
style = hgexport('factorystyle'); style.Color = 'gray';
hgexport(gcf,"figures/alpha.eps",style);


figure;
hold on;
plot(t, y(:,2)','Marker','diamond', 'LineWidth',1, 'Color', [0.3 0.3 0.3]); 
plot(t, infl_e(2,:), '-.', 'LineWidth',2.5, 'Color', [0.3 0.3 0.3]); 
plot(t, y(:,3)','Marker','square', 'LineWidth',1, 'Color', [0.6 0.6 0.6]); 
plot(t, infl_e(3,:), '-.', 'LineWidth',2.5,'Color', [0.6 0.6 0.6]); 
xtickformat('yyyy');
legend('boxoff');
legend({'non-college raw',  'non-college purified', 'college raw', 'college purified'},'fontsize', 12); box off;
ylabel('1-year ahead Inflation expectations', 'fontsize', 15);
set(gcf,'position',[0,0,1000,500]); fontsize(gcf,scale=1.5);
style = hgexport('factorystyle'); style.Color = 'gray';
hgexport(gcf,"figures/1_yr.eps",style);


figure;
hold on;
plot(t, y5(:,2)','Marker','diamond', 'LineWidth',1, 'Color', [0.3 0.3 0.3]); 
plot(t, infl_5e(2,:), '-.', 'LineWidth',2.5, 'Color', [0.3 0.3 0.3]); 
plot(t, y5(:,3)','Marker','square', 'LineWidth',1,'Color', [0.6 0.6 0.6]); 
plot(t, infl_5e(3,:), '-.', 'LineWidth',2.5,'Color', [0.6 0.6 0.6]); 
xtickformat('yyyy');
legend('boxoff');
legend({'non-college raw', 'non-college purified', 'college raw','college purified'},'fontsize', 12); box off;
ylabel('Long-run Inflation expectations', 'fontsize', 15);
set(gcf,'position',[0,0,1000,500]); fontsize(gcf,scale=1.5);
style = hgexport('factorystyle'); style.Color = 'gray';
hgexport(gcf,"figures/5_yr.eps",style);


figure;
hold on;
plot(t, infl_e(2,:) - (alpha(1,:)+pi_actual.*phi(1,:)), '-.', 'LineWidth',2.5,'Color', [0.3 0.3 0.3]); 
plot(t, infl_e(3,:) - (alpha(1,:)+pi_actual.*phi(1,:)), '-', 'LineWidth',2.5,'Color', [0.6 0.6 0.6]); 
xtickformat('yyyy');
legend('boxoff');
legend({'non-college', 'college'},'fontsize', 12); box off;
ylabel('Deviations from full-information', 'fontsize', 15);
set(gcf,'position',[0,0,1000,500]); fontsize(gcf,scale=1.5);
ylim([-6,8])
style = hgexport('factorystyle'); style.Color = 'gray';
hgexport(gcf,"figures/deviations.eps",style);
